<%@ page language="java" import="java.util.*,java.io.*"
         pageEncoding="UTF-8"%>
<%
//    String path = request.getContextPath();
//    String basePath = request.getScheme() + "://"
//            + request.getServerName() + ":" + request.getServerPort()
//            + path + "/";
//    pdf播放采用绝对路径
    String filepath = request.getParameter("filepath").substring(3);
//    得到除去..\的字符串
//    System.out.println(filepath);
//    拼接绝对路径
    String strPdfPath = application.getRealPath("/") + filepath;
//    System.out.println(strPdfPath);

%>

<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width,height=device-height,initial-scale=1.0,maximum-scale=1.0,user-scalable=no">
    <%--<base href="<%=basePath%>">--%>
    <title>PDF文档</title>
</head>
<%
    out.clear();
    out = pageContext.pushBody();
    response.setContentType("application/pdf");

    try {
//        String strPdfPath = new String("D://200701010001.PDF");
//        //判断该路径下的文件是否存在
//        File file = new File(strPdfPath);
        File file = new File(strPdfPath);
        if (file.exists()) {
            DataOutputStream temps = new DataOutputStream(response
                    .getOutputStream());
            DataInputStream in = new DataInputStream(
                    new FileInputStream(strPdfPath));

            byte[] b = new byte[2048];
            while ((in.read(b)) != -1) {
                temps.write(b);
                temps.flush();
            }

            in.close();
            temps.close();
        } else {
            out.print(strPdfPath + " 文件不存在!");
        }

    } catch (Exception e) {
        out.println(e.getMessage());
    }
%>
<body>
<br>
</body>
</html>